import React from "react";
import { Button, Form, Input, Select, Switch } from "antd";
import type { FormInstance } from "antd/es/form";
import { categoryPost } from "@/api/course";
import { CategoryType } from "@/types/course";
import RoleTree from "./role-tree";
import { rolePost } from "@/api/user";

const { Option } = Select;

const layout = {
  labelCol: { span: 6 },
  wrapperCol: { span: 16 },
};

const tailLayout = {
  wrapperCol: { offset: 8, span: 16 },
};

const RoleForm: React.FC = () => {
  const formRef = React.useRef<FormInstance>(null);

  const onFinish = (values: any) => {
    console.log(values);
    rolePost(values);
  };

  const onReset = () => {
    formRef.current?.resetFields();
  };

  return (
    <Form
      {...layout}
      ref={formRef}
      name="control-ref"
      onFinish={onFinish}
      style={{ maxWidth: 600 }}
    >
      <Form.Item name="roleName" label="角色名称" rules={[{ required: true }]}>
        <Input />
      </Form.Item>

      <Form.Item
        label="角色权限"
        name="permission"
        valuePropName="checked"
        rules={[{ required: true }]}
      >
        <RoleTree />
      </Form.Item>

      <Form.Item {...tailLayout}>
        <Button type="primary" htmlType="submit">
          确定
        </Button>
        <Button htmlType="button" onClick={onReset}>
          重置
        </Button>
      </Form.Item>
    </Form>
  );
};

export default RoleForm;
